package app.mvp.contract;

import android.graphics.drawable.ColorDrawable;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Toast;

import app.mvp.BbqbUserBean;
import app.mvp.R;
import app.mvp.base_mvp.BaseActivity;
import app.mvp.utils.StatusBarUtils;
import utils.Base64Utils;
import utils.LogUtils;
import utils.RSAUtils;
import utils.ToastUtils;

/**
 * Created by 刘智强 on 2017/5/3.
 */

public class LoginActivity extends BaseActivity<LoginPresenter, LoginModel> implements LoginView {
    private EditText et_name, et_password;//账号，密码
    private Button btn_login;//登陆
    private RelativeLayout rl_title_bar;

    @Override
    public void loginSuccess(LoginModel loginModel) {
        ToastUtils.myToast(mActivity, loginModel.getApp_login_key());
    }

    @Override
    public void loginFailed(String msg) {
        Log.e(this.getClass().getName(), "登陆失败");
    }

    @Override
    public void showMessage(String msg) {
        Toast.makeText(mActivity, msg, Toast.LENGTH_SHORT).show();

    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    public void initView() {
        et_name = (EditText) findViewById(R.id.et_name);
        et_password = (EditText) findViewById(R.id.et_password);
        btn_login = (Button) findViewById(R.id.btn_login);
        rl_title_bar = (RelativeLayout) findViewById(R.id.rl_title_bar);
        ColorDrawable colorDrawable = (ColorDrawable) rl_title_bar.getBackground();
        StatusBarUtils.setColor(mActivity, colorDrawable.getColor());
    }

    @Override
    public void initClick(View v) {
        switch (v.getId()) {
            case R.id.btn_login:
//                LogUtils.e(RSAUtils.loadPublicKey().toString());
                presenter.getData(mActivity, et_name.getText().toString().trim(), et_password.getText().toString().trim());
//                presenter.login(et_name.getText().toString().trim(), et_password.getText().toString().trim());//发起登陆
                break;

            default:
        }

    }

    @Override
    public void initListener() {
        addOnClickListener(R.id.btn_login);


    }

    @Override
    public void init() {
        presenter.setGetDataFromCache(true);//要缓存该页面接口返回的数据
    }

    @Override
    public void updateUi() {

    }
}
